package com.ch.engine.biz.controller;

import com.ch.common.result.Result;
import com.ch.engine.biz.service.BizCustomerService;
import com.ch.engine.email.EmailSendUtil;
import com.ch.engine.modules.entity.Customer;
import com.ch.engine.modules.service.ICustomerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户web接口
 *
 * @author wangchunhui
 * @date 2024/8/15 17:43
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/customer")
@Slf4j
public class BizCustomerController {

    private final ICustomerService customerService;
    private final EmailSendUtil emailSendUtil;
    private final BizCustomerService bizCustomerService;

    /**
     * 查询所有列表
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @GetMapping("/list")
    public Result page() {
        List<Customer> customerList = customerService.list();
        return Result.SUCCESS(customerList);
    }

    /**
     * 发送简单邮件测试
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @GetMapping("/send/email")
    public Result sendEmail() {
        emailSendUtil.sendEmail("643736249@qq.com", "试一下主题", "你好啊");
        return Result.SUCCESS();
    }

    /**
     * mybatisPlus.saveBatch测试
     *
     * @return Result
     * @author wangchunhui
     * @date 2024/8/15 17:43
     */
    @GetMapping("/testSaveBatch")
    public Result testSaveBatch() {
        bizCustomerService.testSaveBatch();
        return Result.SUCCESS();
    }

    /**
     * 写文件
     *
     * @param response response
     * @return com.ch.common.result.Result
     * @author wangchunhui
     * @date 2024/9/10 15:45
     */
    @PostMapping(value = "/write/excel")
    public Result writeExcel(HttpServletResponse response) {
        bizCustomerService.writeExcel(response);
        return Result.SUCCESS();
    }
}
